<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
								xmlns:p="http://www.example.org/products"
								xmlns:map = "xalan://java.util.HashMap"
								xmlns:list = "xalan://java.util.ArrayList"
								extension-element-prefixes="map list" >
	<xsl:output method="html" />
	
	<xsl:param name="categoryName" />
	<xsl:param name="subcategoryName" />
	<xsl:template match="/">
		<xsl:call-template name="add-goods" />
	</xsl:template>
	
	<xsl:template name="add-goods">
		<xsl:param name="errors" select="map:new()"/>
		<xsl:param name="model" select="''"/>
		<xsl:param name="producer" select="''"/>
		<xsl:param name="color" select="''"/>
		<xsl:param name="date" select="''"/>
		<xsl:param name="price" select="''"/>
		
		<html>
			<head>
				<title>Adding product</title>
				<link type="text/css" rel="stylesheet" href="view/styles/style.css" />
				<script type="text/javascript" src="view/js/script.js" ></script>
			</head>
			<body>
				<div id="main">
					<div id="header">
						<h2>
							ProductStore
						</h2>	
					</div>
					<div id="content">
						<h2><xsl:value-of select="$categoryName" /> &gt; &gt;
							<xsl:value-of select="$subcategoryName" />
						</h2>
						<h3>Adding goods</h3>
						<form method="POST" action="productAction.do?method=saveGoods&amp;categoryName={$categoryName}&amp;subcategoryName={$subcategoryName}">
						<table class="add-goods">
							<tr>
								<th>Producer:</th>
								<td>
									<input type="text" name="producer" value="{$producer}"/>
								</td>
								<td class="error-message">
									<xsl:call-template name="print-errors">
										<xsl:with-param name="inputName" select="'producer'" />
										<xsl:with-param name="errors" select="$errors" />
									</xsl:call-template>
								</td>
							</tr>
							<tr>
								<th>Model:</th>
								<td>
									<input type="text" name="model" value="{$model}"/>
								</td>
								<td class="error-message">
									<xsl:call-template name="print-errors">
										<xsl:with-param name="inputName" select="'model'" />
										<xsl:with-param name="errors" select="$errors" />
									</xsl:call-template>
								</td>
							</tr>
							<tr>
								<th>Date of issue:</th>
								<td>
									<input type="text" name="date" value="{$date}"/>
								</td>
								<td class="error-message">
									<xsl:call-template name="print-errors">
										<xsl:with-param name="inputName" select="'date'" />
										<xsl:with-param name="errors" select="$errors" />
									</xsl:call-template>
								</td>
							</tr>
							<tr>
								<th>Color:</th>
								<td>
									<input type="text" name="color" value="{$color}"/>	
								</td>
								<td class="error-message">
									<xsl:call-template name="print-errors">
										<xsl:with-param name="inputName" select="'color'" />
										<xsl:with-param name="errors" select="$errors" />
									</xsl:call-template>
								</td>
							</tr>
							<tr>
								<th>Price:</th>
								<td>
									<input type="text" name="price" value="{$price}" id="price"/>
									<input type="checkbox" name="notInStock" id="notInStock" onclick="addGoods();"/>
									<label>
										Not in stock
									</label>
								</td>
								<td class="error-message">
									<xsl:call-template name="print-errors">
										<xsl:with-param name="inputName" select="'price'" />
										<xsl:with-param name="errors" select="$errors" />
									</xsl:call-template>
								</td>
							</tr>
						</table>
						<input type="submit" name="save" value="Save" style="width: 100px; float:left"/>
					</form>
					<div>
						<form method="POST" action="productAction.do?method=goodsList&amp;categoryName={$categoryName}&amp;subcategoryName={$subcategoryName}">
							<input type="submit" value="Back" style="width: 100px; float:left; margin-top: -19;"/>
						</form>
					</div>
					</div>
					<div id="buffer">				
					</div>
				</div>
				<div id="footer">
					<p>Copyright &#169; EPAM 2012. All rights reserved.</p>
				</div>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template name="print-errors">
		<xsl:param name="inputName" />
		<xsl:param name="errors" />
		<xsl:if test="map:containsKey($errors, $inputName)">
			<xsl:variable name="errorList" select="map:get($errors, $inputName)" />
			<ul>
				<xsl:call-template name="iterate-errors">
					<xsl:with-param name="errorList" select="$errorList" />
					<xsl:with-param name="count" select="list:size($errorList) - 1" />
				</xsl:call-template>
			</ul>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="iterate-errors">
		<xsl:param name="count" />
		<xsl:param name="errorList" />
		<xsl:if test="$count > -1">
			<li>
				<xsl:value-of select="list:get($errorList, $count)" />
			</li>
			<xsl:call-template name="iterate-errors">
				<xsl:with-param name="errorList" select="$errorList"/>
				<xsl:with-param name="count" select="$count - 1" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>	
</xsl:stylesheet>